﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class aspnet_admin_bock_Link_CX_Link_AddNew : System.Web.UI.Page
{    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();


    /// <summary>
    /// 站点通用方法类
    /// </summary>
    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();
    public string str = "";
    DataTable NewDt = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            NewDt.Columns.Add("东东");
            NewDt.Columns.Add("Conts");
            ShowTree(0);
            CX_Column_id.DataSource = NewDt.DefaultView;
            CX_Column_id.DataTextField = "Conts";
            CX_Column_id.DataValueField = "东东";
            CX_Column_id.DataBind();
        }
        //outClassName();
    }

    /// <summary>
    /// 返回 一个类下所有的方法名
    /// </summary>
    /// <returns></returns>
    protected void outClassName()
    {
        Type t = typeof(TongUse);
        System.Reflection.MethodInfo[] Methods = t.GetMethods();
        for (int i = 0; i < Methods.Length; i++)
        {
            Response.Write(Methods[i].Name
                +"<br/>");
        }
    }

    int ii = 0;
    /// <summary>
    /// 返回菜单显示的HTML代码
    /// </summary>
    /// <param name="select">显示的展次</param>
    /// <returns></returns>
    public void ShowTree(int select)
    {
        string sql;
        int i = 0;
        DataTable MyDt = new DataTable();
        sql = "Select * From CX_Column where CX_Column_LX<>3 and CX_Column_followid =" + select + " order by CX_Column_id desc";
        try
        {

            MyDt = TextData.SqlataSet(sql).Tables[0];//创建DataTable MyDt
        }
        catch (Exception ex)
        {
            TextData.Err(ex.Message);

        }
        for (i = 0; i < MyDt.Rows.Count; i++)//遁环记录集
        {
            if (select == 0)//如果只一有层的话
            {

                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            else
            {
                DataRow Row = NewDt.NewRow();
                Row[0] = MyDt.Rows[i]["CX_Column_id"].ToString();
                Row[1] = TextData.EStr(ii, "…") + MyDt.Rows[i]["CX_Column_Name"].ToString();
                NewDt.Rows.Add(Row);

            }
            ii = ii + 1;
            ShowTree(int.Parse(MyDt.Rows[i]["CX_Column_id"].ToString()));//调用自己显示菜单ＨＴＭＬ
            ii -= 1;

        }


    }
    //保存事件
    protected void Button1_Click(object sender, EventArgs e)
    {
        //添加新LINK数据
        if (IsPostBack)
        {
            ///sql语句
            string Csql = "";
            string CX_link_LX ="";
            //link类型
            try
            {
                 CX_link_LX = Request.Form["CX_link_LX"].Trim();
            }
            catch
            {
                 CX_link_LX = "文字";
            }

            ///添加数据
            try
            {

                if (int.Parse(CX_link_Sort.Text.Trim()) <= 99999)
                {
                    Csql = "insert into [CX_link] ([CX_Column_id] ,[CX_link_Name] ,[CX_link_LX],[CX_link_Pic],[CX_link_Cont], [CX_link_Sort],[CX_link_linkUrl] ) values(";
                    Csql += "" + CX_Column_id.SelectedValue + " ,'" + Server.HtmlEncode(CX_link_Name.Text.Trim()) + "', '" + CX_link_LX + "','" + Server.HtmlEncode(CX_link_Pic.Text.Trim()) + "','" + Server.HtmlEncode(CX_link_Cont.Text.Trim()) + "'," + CX_link_Sort.Text.Trim() + ",'" + CX_link_linkUrl.Text.Replace("'","'") + "')";
                   
                    TextData.SqlDataSave(Csql);

                    tt.Text = "添加" + CX_link_Name.Text.Trim() + " 成功";
                    CX_link_Name.Text = "";
                }
            }
            catch
            {


            }
           
                            
          
        }
    }
}
